<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2019/4/7
 * Time: 16:53
 */

namespace common\logics\rechargerecord;

use common\widgets\Tool;
use Yii;
use yii\base\BaseObject;

class RechargeRecordLogic extends BaseObject implements IRechargeRecord
{
    /** @var \common\sources\read\businessrechargerecord\BusinessRechargeRecordAccess $RBusinessRechargeRecordAccess ****/
    private $RBusinessRechargeRecordAccess;

    public function init()
    {
        $this->RBusinessRechargeRecordAccess = Yii::$container->get("RBusinessRechargeRecordAccess");
        parent::init(); // TODO: Change the autogenerated stub
    }
    //获取每页的数据
    public function getRechargeRecord($data)
    {
        if(empty($data['bus_id']))
        {
            return Tool::returnJson([],401,"商家用户id不能为空");
        }
        if(empty($data['safetyCode']))
        {
            return Tool::returnJson([],402,"安全码不能为空");
        }
        if($data['safetyCode'] != md5($data['bus_id']))
        {
            return Tool::returnJson([],403,"安全码不正确");
        }
        //统计商家充值数据
        $count = $this->RBusinessRechargeRecordAccess->getCount($data);
        $list = [];
        if($count >0)
        {
            $list = $this->RBusinessRechargeRecordAccess->getList($data);
            foreach ($list as &$item)
            {
                $item['create_time'] = isset($item['create_time']) ? date('Y-m-d H:i:s',$item['create_time']): '';
            }
        }
        return Tool::returnJson([
            "list" => $list,
            "page_num" => $data['page_num'],
            "count" => $count,
            "limit" => $data['limit']
        ],200,"成功");


    }
}